const webToastObj = (params) => {
  // 设置信息框停留的默认时间
  let time = params.time;
  if (time === undefined || time === '') {
    time = 1500;
  }
  const el = document.createElement("div");
  el.setAttribute("class", "web-toast");

  // 根据传入的图片路径添加图标
  let iconHtml = '';
  if (params.icon) {
    iconHtml = `<img src="${params.icon}" alt="toast-icon" class="web-toast-icon">`;
  }

  el.innerHTML = `${iconHtml}${params.message}`;
  document.body.appendChild(el);
  el.classList.add("fadeIn");
  setTimeout(() => {
    el.classList.remove("fadeIn");
    el.classList.add("fadeOut");
    // 监听动画结束，移除提示信息元素
    el.addEventListener("animationend", () => {
      document.body.removeChild(el);
    });
    el.addEventListener("webkitAnimationEnd", () => {
      document.body.removeChild(el);
    });
  }, time);
};

// 将 webToastObj 函数作为 Vue 实例的方法导出
export default {
  install: (Vue) => {
    Vue.prototype.$webToastObj = webToastObj;
  }
};